package com.tj.admin.auth.vo;


import com.fqgj.exception.common.ApplicationException;
import com.tj.bo.common.conf.enums.RestCodeEnum;

/**
 * @author poyangchen
 */
public class RequestLocalInfo {

    private static final ThreadLocal<Boolean> currentEnvIsTest = new ThreadLocal<>();
    private static final ThreadLocal<UserAccessInfo> currentUser = new ThreadLocal<>();


    public static void clearThreadLocal() {
        currentUser.remove();
    }

    public static void putCurrentUser(UserAccessInfo user) {
        if (user == null) {
            throw new ApplicationException(RestCodeEnum.USER_NOT_EXIST_ERROR);
        }

        RequestLocalInfo.currentUser.set(user);
    }

    public static UserAccessInfo getCurrentUser() {
        return currentUser.get();
    }


    public static void putCurrentEnvIsTest(Boolean env) {

        RequestLocalInfo.currentEnvIsTest.set(env);
    }
}
